﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClientAPI
{
    class ProjectController
    {
        private Dictionary<string, string[]> _projects;

        internal ProjectController()
        {
            _projects = new Dictionary<string, string[]>();
        }

        internal void AddProject(string name, string info)
        {
            string[] tempArray = info.Split('µ');
            if (_projects.ContainsKey(name))
                _projects[name] = tempArray;
            else
                _projects.Add(name, tempArray);
        }

        internal void RemoveProject(string name)
        {
            if (_projects.Keys.Contains(name))
            {
                _projects.Remove(name);
            }
        }

        internal string[] GetProjectValues(string key)
        {
            string[] tempArray;

            _projects.TryGetValue(key, out tempArray);

            return tempArray;
        }

        internal string[] GetProjectsArray()
        {
            return _projects.Keys.ToArray();
        }

        internal List<string> GetProjectsList()
        {
            List<string> temp = new List<string>();
            foreach (string i in _projects.Keys)
            {
                temp.Add(i);
            }
            return temp;
        }

        internal string[] GetProjectSearch(string value)
        {
            List<string> tempReturn = new List<string>();
            char[] valueArray = value.ToCharArray();

            foreach(string i in _projects.Keys)
            {
                int closeness = 0;
                char[] tempArray = i.ToCharArray();
                for (int x = 0; x < tempArray.Length && x < valueArray.Length; x++)
                {
                    if (tempArray[x] == valueArray[x])
                        closeness++;
                }
                if ((closeness / valueArray.Length) * 100 >= 45)
                {
                    tempReturn.Add(i);
                }
            }

            tempReturn.Add(" ");


            return tempReturn.ToArray();
        }
    }
}
